package com.zeroone.star.ee.controller;

import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import com.zeroone.star.ee.entity.Document;
import com.zeroone.star.ee.mapper.DocumentMapper;
import com.zeroone.star.project.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 测试消息发布控制器
 * @Author lyx
 * @since 2024/11/8 21:54
 */

@RestController
@RequestMapping("ee")
@Api(tags = "ee")
public class EeController {
    @Resource
    private DocumentMapper mapper;

    @ApiOperation("添加数据")
    @PostMapping("add")
    public JsonVO<Integer> add(String title, String content){
        Document document = new Document();
        document.setTitle(title);
        document.setContent(content);
        return JsonVO.success(mapper.insert(document));
    }

    @ApiOperation("查找数据")
    @GetMapping("search")
    public JsonVO<List<Document>> find(String title){
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.like(Document::getTitle,title);
        return JsonVO.success(mapper.selectList(wrapper));
    }
}
